package com.ssh.tts.cui;

import java.util.List;
import java.util.Scanner;

import com.ssh.tts.model.IUser;
import com.ssh.tts.service.UserService;

public class UserCUI {
	
	private static UserService userService = new UserService();
	/**
	 * 注册
	 */
	public static void registerUser() {
		System.out.println("请输入个人信息");
		Scanner input=new Scanner(System.in);
		System.out.print("名字：");
		String name=input.nextLine();
		System.out.print("密码：");
		String password=input.nextLine();
		System.out.print("性别：");
		String sex=input.nextLine();
		System.out.print("身份证：");
		String identifiy=input.nextLine();
		System.out.print("手机号：");
		String phone=input.nextLine();
		
		try {
			userService.register(new IUser(0, name, password, sex, identifiy, phone));
			System.out.println("注册成功");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		//input.close();
	}
	
	/**
	 * 登陆
	 * @return 
	 */
	public static List<IUser> login() {
		Scanner input=new Scanner(System.in);
		System.out.println("欢迎登陆");
		System.out.print("名字：");
		String name=input.nextLine();
		System.out.print("密码：");
		String password=input.nextLine();
		List<IUser> user = null;
		try {
			user = userService.login(new IUser(0, name, password, "", "", ""));
			System.out.println("登陆成功");
		} catch (Exception e) {
			System.out.println(e.getMessage());
			login();
		}
		return user;
	}
}
